package pulsar;

import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.PulsarClientException;

/**
 * @author pzy
 */
public class Pub {
    public static void main(String[] args) throws PulsarClientException {
        PulsarClient client = PulsarClient.builder()
                .serviceUrl("pulsar://192.168.56.101:6650")
                .build();
        Producer<byte[]> producer = client.newProducer()
                .topic("my-topic")
                .create();
        for (int i = 0; i < 20; i++) {
            MessageId messageId = producer.send(("你好" + i).getBytes());
            System.out.println("发送成功：messageId=" + messageId);
        }
    }
}
